style: Apply same matrix conversion as gdk_draw_layout() did
authorBenjamin Otte <otte@redhat.com>
Sat, 7 Aug 2010 00:14:10 +0000 (02:14 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 10 Aug 2010 19:02:31 +0000 (21:02 +0200)
This is only necessary for GtkLabel with an angle set as no other widget
rotates text.
Note that the label code does not need these adjustments as those paths
are only taken when the label is not rotated.

gtk/gtkstyle.c

index 9b615d4fad1a272c5362d1f5039d73875d31c2cb..853aa8b8402668d038c4540fe707e49d3408f684 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <gobject/gvaluecollector.h>
 #include "gtkmarshalers.h"
+#include "gtkpango.h"
 #include "gtkrc.h"
 #include "gtkspinbutton.h"
 #include "gtkstyle.h"
@@ -4191,6 +4192,7 @@ gtk_default_draw_layout (GtkStyle        *style,
 {
   cairo_t *cr;
   GdkColor *gc;
+  const PangoMatrix *matrix;
 
   cr = gdk_cairo_create (window);
 
@@ -4200,17 +4202,43 @@ gtk_default_draw_layout (GtkStyle        *style,
       cairo_clip (cr);
     }
 
+  matrix = pango_context_get_matrix (pango_layout_get_context (layout));
+  if (matrix)
+    {
+      cairo_matrix_t cairo_matrix;
+      PangoMatrix tmp_matrix;
+      PangoRectangle rect;
+      
+      cairo_matrix_init (&cairo_matrix,
+                         matrix->xx, matrix->yx,
+                         matrix->xy, matrix->yy,
+                         matrix->x0, matrix->y0);
+
+      pango_layout_get_extents (layout, NULL, &rect);
+      pango_matrix_transform_rectangle (matrix, &rect);
+      pango_extents_to_pixels (&rect, NULL);
+                                          
+      tmp_matrix = *matrix;
+      cairo_matrix.x0 += x - rect.x;
+      cairo_matrix.y0 += y - rect.y;
+
+      cairo_set_matrix (cr, &cairo_matrix);
+    }
+  else
+    cairo_translate (cr, x, y);
+
   if (state_type == GTK_STATE_INSENSITIVE)
     {
+      cairo_save (cr);
       gdk_cairo_set_source_color (cr, &style->white);
-      cairo_move_to (cr, x + 1, y + 1);
+      cairo_move_to (cr, 1, 1);
       pango_cairo_layout_path (cr, layout);
       cairo_fill (cr);
+      cairo_restore (cr);
     }
 
   gc = use_text ? &style->text[state_type] : &style->fg[state_type];
 
-  cairo_move_to (cr, x, y);
   gdk_cairo_set_source_color (cr, gc);
 
   pango_cairo_show_layout (cr, layout);